package com.mk.common.clone;

import java.text.ParseException;
import java.util.Date;

import org.junit.Test;

import com.mk.common.util.DateUtil;

/**
 * 深度克隆 && 浅度克隆
 * @author 上官雅晴
 *
 */
public class CloneDemo {
	
	@Test
	public void test1() throws Exception {
		Date serviceDate = DateUtil.ymd.parse("2021-04-12");
		Date serviceDat1e1 = DateUtil.ymd.parse("2021-05-22");
		Car car = new Car();
		car.setId("daf23fb2823by4v1d8h");
		car.setNum(3);
		car.setServiceDate( serviceDate );
		car.setWeight(1.28);
		
		Car c = (Car) car.clone();
		
		System.out.println(car);
		System.out.println("--------------");
		System.out.println("克隆后-");
		c.setServiceDate(serviceDat1e1);
		
		System.out.println(car);
		System.out.println(c);
		
		System.out.println(c.getServiceDate()== car.getServiceDate()); //false
	}
	
	
	@Test
	public void test2() throws Exception {
		Date serviceDate = DateUtil.ymd.parse("2021-04-12");
		Date serviceDat1e1 = DateUtil.ymd.parse("2021-05-22");
		Car car = new Car();
		car.setId("daf23fb2823by4v1d8h");
		car.setNum(3);
		car.setServiceDate( serviceDate );
		car.setWeight(1.28);
		
		Car c = (Car) car.clone();
		//--------
		System.out.println(car==c); //false
		System.out.println(car.getServiceDate() == c.getServiceDate() ); //true
	}
	
	@Test
	public void test3() throws Exception {
		Date serviceDate = DateUtil.ymd.parse("2021-04-12");
		Date serviceDat1e1 = DateUtil.ymd.parse("2021-05-22");
		Car car = new Car();
		car.setId("daf23fb2823by4v1d8h");
		car.setNum(3);
		car.setServiceDate( serviceDate );
		car.setWeight(1.28);
		//克隆
		Car c = (Car) car.clone();
		System.out.println(car);
		//更改
		car.setServiceDate(serviceDat1e1);
		System.out.println(c);
		System.out.println(car);
	}
	
	
	
}
